package com.xiaotu.spider.maoyan.pipeline;

import java.util.List;
import org.springframework.stereotype.Component;

import com.xiaotu.common.model.MaoYanSplitBoxofficeDetailModel;
import com.xiaotu.common.model.MaoYanSplitBoxofficeSummaryModel;
import com.xiaotu.common.util.Constants;
import com.xiaotu.common.util.DataRedisKeyUtils;
import com.xiaotu.spider.APipeline;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;

/***
 * 猫眼网大分账票房明细
 * @author Administrator
 *
 */
@Component("MaoYanNetMovieSplitBoxofficeDetailPipeline")
public class MaoYanNetMovieSplitBoxofficeDetailPipeline extends APipeline {

	@Override
	protected void doProcess(ResultItems resultItems, Task task) {
		List<MaoYanSplitBoxofficeDetailModel> splitBoxofficeDetailList = resultItems.get(MaoYanSplitBoxofficeDetailModel.class.getName());
        if (splitBoxofficeDetailList != null && !splitBoxofficeDetailList.isEmpty())
        {
            String key = DataRedisKeyUtils.getKey(Constants.DataRedisKey.MOVIE_SPLIT_DETAIL_YYYYMMDD);
            for(MaoYanSplitBoxofficeDetailModel obj : splitBoxofficeDetailList){
            	cacheHandler.hSet(key, obj.getTv_dataid()+"_"+obj.getId(), obj);
            }
            cacheHandler.setCacheTimeout(key);
        }
        
        MaoYanSplitBoxofficeSummaryModel summaryModel = resultItems.get(MaoYanSplitBoxofficeSummaryModel.class.getName());
        if(null != summaryModel){
        	String key = DataRedisKeyUtils.getKey(Constants.DataRedisKey.MOVIE_SPLIT_SUMMARY_YYYYMMDD);
        	cacheHandler.hSet(key, summaryModel.getTv_dataid()+"_"+summaryModel.getId(), summaryModel);
        	cacheHandler.setCacheTimeout(key);
        }
	}

}
